package com.tjetc.controller;

import com.tjetc.common.JsonResult;
import com.tjetc.entity.CaregiverInfo;
import com.tjetc.entity.ElderInfo;
import com.tjetc.service.CaregiverInfoService;
import com.tjetc.service.ElderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("caregiverinfo")
public class CaregiverInfoController {
    @Autowired
    private CaregiverInfoService caregiverInfoService;

    @RequestMapping("detail/{caregiverId}")
    public JsonResult detail(@PathVariable("caregiverId") Long id) {
        return caregiverInfoService.findById(id);
    }
    @RequestMapping("page")
    public JsonResult page(@RequestParam(value = "name", required = false,defaultValue = "") String name,
                           @RequestParam(value = "pageNo",required = false,defaultValue = "1") Integer pageNo,
                           @RequestParam(value = "pageSize",required = false,defaultValue = "2") Integer pageSize) {
        return caregiverInfoService.findPage(name,pageNo,pageSize);
    }
    @RequestMapping("delete/{caregiverId}")
    public JsonResult delete(@PathVariable("caregiverId") Long id) {
        return caregiverInfoService.deleteById(id);
    }
    //接收参数格式是json
    @RequestMapping("save")
    public JsonResult save(@RequestBody CaregiverInfo caregiverInfo){
        return caregiverInfoService.save(caregiverInfo);
    }
    @RequestMapping("edit/{caregiverId}")
    public JsonResult edit(@PathVariable("caregiverId") Long id) {
        return caregiverInfoService.findByEmployeeId(id);
    }
    @RequestMapping("getList")
    public JsonResult getList() {
        return caregiverInfoService.getCareGiverList();
    }
}
